# Process raw employment data got from BLS QCEW Database.


BEGIN {
  OFS = ","
  split("Jan Feb Mar Apr	May	Jun	Jul	Aug	Sep	Oct	Nov	Dec Annual", mons)
  print "County", "Year", "Month", "Employment"
  flag = 0
}

{
  if (flag) {
    if (length($1) > 9  && NF > 3) {
      part = part " " $0
      next
    }
    flag = 0
    line = part " " $0
    n = split(line,fields)
    year = fields[1]
    for(i=2; i<=n; ++i) {
      split(fields[i], w, "\(")
      print county, year, mons[i-1], w[1]
    }
    next
  }

  if ($1 ~ /^\*Area/) {
    county = substr($2,2)
    if ($4 ~ /County/ || $NF ~ /Statewide/) {
      county = county " " $3
    }
    next
  }

  if ($1 ~ /^20[01][0-9]$/) {
    if (NF<14) {
      flag = 1
      part = $0
      next
    }
    year = $1
    for(i=2; i<=NF; ++i) {
    
      split($i,w,"\(")
      print county, year, mons[i-1], w[1]
    }
  }
}
